package com.stylefeng.guns.modular.vpn.config;

import com.stylefeng.guns.modular.vpn.mquartz.SpringQuartzJobFactory;
import com.stylefeng.guns.modular.vpn.utils.BusinessTaskUtil;
import com.stylefeng.guns.modular.vpn.utils.ConnectUtil;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * @Description 定时器 任务调度管理器
 * @Author Mr.God
 * @Date 2020-03-15 16:12
 **/
@Configuration
public class QuartzConfig {

    @Autowired
    private SpringQuartzJobFactory jobFactory;

    @Bean(name = "businessTaskUtil")
    public BusinessTaskUtil businessTaskUtil(){
        return new BusinessTaskUtil();
    }

    @Bean(name = "connectUtil")
    public ConnectUtil connectUtil(){
        return new ConnectUtil();
    }

    /**
     * 配置SchedulerFactoryBean
     * 将一个方法产生为Bean并交给Spring容器管理
     * @return
     */
    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(){
        SchedulerFactoryBean factory = new SchedulerFactoryBean();
        factory.setOverwriteExistingJobs(true);
        factory.setJobFactory(jobFactory);
        return factory;
    }

    @Bean(name = "scheduler")
    public Scheduler scheduler() {
        return schedulerFactoryBean().getScheduler();
    }

}
